package com.tedu.ds.role.service.impl;

import com.tedu.ds.role.mapper.RoleMapper;
import com.tedu.ds.role.pojo.dto.RoleParam;
import com.tedu.ds.role.pojo.dto.RoleQuery;
import com.tedu.ds.role.pojo.entity.Role;
import com.tedu.ds.role.pojo.vo.RoleVO;
import com.tedu.ds.role.service.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<RoleVO> select(RoleQuery roleQuery) {
        return roleMapper.select(roleQuery);
    }

    @Override
    public void save(RoleParam roleParam) {
        Role role=new Role();
        BeanUtils.copyProperties(roleParam,role);
        if (role.getId()==null){
            roleMapper.insert(role);
        }else {
            roleMapper.update(role);
        }
    }

    @Override
    public void deleteById(Integer id) {
        roleMapper.delete(id);
    }
}
